 //
//  PreviewView.m
//  ICrEAM
//
//  Created by Cty on 2016/10/29.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "PreviewView.h"
#import "PreviewBaseItemView.h"
#import "ICMAppearanceCheckView.h"
#import "PreviewItemAndComponentView.h"
#import "PreviewItemsModel.h"
#import "PreviewCompsModel.h"
#import "ICMCustomerInfoView.h"
#import "ICMCustomerInfoModel.h"
#import "PreviewPackageView.h"
#import "PreviewActivityView.h"
#import "SuperViewController.h"
#define DisplayWidth      ActualWidth(984)
#define StartLeftDistance      ActualWidth(80)
#define ItemWidth      ActualWidth(260)
#define ItemHeight      ActualWidth(50)

@interface PreviewView ()

@property (nonatomic,strong) NSString *repairTypeNamePart;

@property (nonatomic,strong) NSString *repairTypeNameLabour;

@property (nonatomic,strong) NSMutableArray *labourArray;

@property (nonatomic,strong) NSMutableArray *partArray;

@end

@implementation PreviewView

-(NSMutableArray *)labourArray{
    if (!_labourArray) {
        _labourArray = [NSMutableArray array];
    }
    return _labourArray;
}

-(NSMutableArray *)partArray{
    if (!_partArray) {
        _partArray = [NSMutableArray array];
    }
    return _partArray;
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self){
        
        
    }
    
    return self;
}

- (void)setUpChildView{
    
    //self.basicInfoModel.LICENSE; //接车单基本信息
    //   self.checkAppearanceDownModel;
    //   self.checkAppearanceTopModel;
    // self.activityModel;
    //  self.carePackageModel;
    //  self.carePackageDownModel;
    //  self.partsTopModel;
    //self.repairEventModel;
    //   self.repairPartsModel;
    
    
    UILabel *label  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(20),ActualWidth(20), DisplayWidth, ActualHeight(20))];
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = TitleColor_Dark;
    label.font = NaviFont;
    label.text = @"接车单基本信息";
    
    UIButton *printButton = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-100, 0, 25, 25)];
    [printButton setBackgroundImage:[UIImage imageNamed:GetCar_Print] forState:UIControlStateNormal];
    [printButton addTarget:self action:@selector(clickPrintButton) forControlEvents:UIControlEventTouchUpInside];
    
    //1.车辆信息块
    //第一行分割线
    UIView *firstLine = [[UIView alloc] initWithFrame:CGRectMake(label.x, label.bottomEdge+ActualHeight(20), DisplayWidth+ActualWidth(20), 1)];
    
    firstLine.backgroundColor = BackgroundColor_Gray;
    
    
    //车牌图片
    UIImage *image = [UIImage imageNamed:Appointment_Car];
    
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    
    imageView.frame =CGRectMake(ActualHeight(20), firstLine.bottomEdge+ActualHeight(48), ActualWidth(30), ActualHeight(30));
    
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    //车牌号
    PreviewBaseItemView *carNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, firstLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                   @"车牌号" andSubTitle:self.basicInfoModel.LICENSE];
    //VIN
    PreviewBaseItemView *vinNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(carNum.rightEdge, firstLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                   @"VIN" andSubTitle:self.basicInfoModel.VIN];
    
    //购车发票日期
    PreviewBaseItemView *invoicesDate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(vinNum.rightEdge, firstLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                         @"购车发票日期" andSubTitle:self.isInner?self.basicInfoModel.SALES_DATE:[ICrEAMTool getDateWithTimeInterval:self.basicInfoModel.SALES_DATE]];
    
    //行驶里程
    PreviewBaseItemView *mileage = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(invoicesDate.rightEdge, firstLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                    @"行驶里程" andSubTitle:self.basicInfoModel.IN_MILEAGE];
    //车型
    PreviewBaseItemView *carType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, carNum.bottomEdge +ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                    @"车型" andSubTitle:[NSString stringWithFormat:@"%@|%@",self.basicInfoModel.MODEL_CODE,self.basicInfoModel.MODEL_NAME]];
    
    
    //油量
    PreviewBaseItemView *oilMass = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(carType.rightEdge, carNum.bottomEdge +ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                    @"油量" andSubTitle:[self.basicInfoModel.OIL_REMAIN.description stringByAppendingString:@"%"]];
    
    [self addSubview:firstLine];
    [self addSubview:imageView];
    [self addSubview:label];
    [self addSubview:carNum];
    [self addSubview:vinNum];
    [self addSubview:invoicesDate];
    [self addSubview:mileage];
    [self addSubview:carType];
    [self addSubview:oilMass];
    if ([self.basicInfoModel.RECEPTION_STATUS isEqualToString:ICMEnumIntToString(ICMEnumReceptionStatus35521002)]) {
        [self addSubview:printButton];
    }
    
    
    //2.车主信息块
    //第二行分割线
    UIView *secondLine = [[UIView alloc] initWithFrame:CGRectMake(carType.x, oilMass.bottomEdge+ActualHeight(20), ActualWidth(1024)-carType.x, 1)];
    
    secondLine.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:secondLine];
    
    //车主图片
    //车牌信息
    UIImage *imageOwner = [UIImage imageNamed:Appointment_CarOwner];
    // 当没有设置imageView的frame时
    // 图片控件所占的区域与加载的图片大小保持一致
    UIImageView *imageViewOwner = [[UIImageView alloc]initWithImage:imageOwner];
    
    imageViewOwner.frame =CGRectMake(ActualHeight(20), secondLine.bottomEdge+ActualHeight(48), ActualWidth(30), ActualHeight(30));
    
    //设置图片的显示模式
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    [self addSubview:imageViewOwner];
    
    //车主姓名
    PreviewBaseItemView *ownerName = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, secondLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                      @"车主姓名" andSubTitle:self.basicInfoModel.OWNER_NAME];
    
    [self addSubview:ownerName];
    //车主手机
    PreviewBaseItemView *ownerPhone = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(ownerName.rightEdge, secondLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                       @"车主手机" andSubTitle:self.basicInfoModel.OWNER_MOBILE];
    
    [self addSubview:ownerPhone];
    
    //预约人姓名
    PreviewBaseItemView *appointedName = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(ownerPhone.rightEdge, secondLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                          @"送修人姓名" andSubTitle:self.basicInfoModel.DELIVERER];
    [self addSubview:appointedName];
    //预约人手机
    PreviewBaseItemView *appointedPhone = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(appointedName.rightEdge, secondLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                           @"送修人手机" andSubTitle:self.basicInfoModel.DELIVERER_MOBILE];
    [self addSubview:appointedPhone];
    //车主性质
    

    
    PreviewBaseItemView *ownerType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, appointedPhone.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                      @"车主性质" andSubTitle:StrIsZero_gdm(self.basicInfoModel.OWNER_PROPERTY)?@"":[ICrEAMTool getCodeModelForCode:self.basicInfoModel.OWNER_PROPERTY].desc];
    
    [self addSubview:ownerType];
    
    //3.详细信息
    //第三行分割线
    UIView *thirdLine = [[UIView alloc] initWithFrame:CGRectMake(ownerType.x, ownerType.bottomEdge+ActualHeight(20), ActualWidth(1024)-carType.x, 1)];
    
    thirdLine.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:thirdLine];
    
    
    //图片
    UIImage *detail = [UIImage imageNamed:GetCar_CarInfo];
    // 当没有设置imageView的frame时
    // 图片控件所占的区域与加载的图片大小保持一致
    UIImageView *imageViewdetail = [[UIImageView alloc]initWithImage:detail];
    
    imageViewdetail.frame =CGRectMake(ActualHeight(20), thirdLine.bottomEdge+ActualHeight(105), ActualWidth(30), ActualHeight(30));
    
    //设置图片的显示模式
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    [self addSubview:imageViewdetail];
    
    //接车日期
    PreviewBaseItemView *receiveDate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, thirdLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                        @"接车日期" andSubTitle:self.isInner?(StrIsZero_gdm(self.basicInfoModel.RECEPTION_DATE)?@"":[ICrEAMTool getDateHourAndMinWithTimeInterval:self.basicInfoModel.RECEPTION_DATE]):(StrIsZero_gdm(self.basicInfoModel.RECEPTION_DATE)?@"":[ICrEAMTool getDateHourAndMinWithTimeInterval:self.basicInfoModel.RECEPTION_DATE])];
    
    [self addSubview:receiveDate];
    
    //接待服务顾问
    PreviewBaseItemView *reception = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(receiveDate.rightEdge, thirdLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                      @"接待服务顾问" andSubTitle:self.isInner?[ICrEAMUser shareICrEAMUser].user_name:self.basicInfoModel.SERVICE_ADVISOR_NAME];
    
    [self addSubview:reception];
    
    //维修类型
    NSMutableArray *repiarDescs = [NSMutableArray array];
    NSArray *repiarCodes = [self.basicInfoModel.REPAIR_TYPE_CODE componentsSeparatedByString:@";"];
    for (NSString *code in repiarCodes) {
        NSString *desc = [ICrEAMTool getRepiarTypeDescWithRepiarCode:code];
        [repiarDescs addObject:desc];
    }
    PreviewBaseItemView *repireType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(reception.rightEdge, thirdLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                       @"维修类型" andSubTitle:[repiarDescs componentsJoinedByString:@","]];
    [self addSubview:repireType];
    
    //接车单号
    PreviewBaseItemView *oddNumber = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(repireType.rightEdge, thirdLine.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                      @"接车单号" andSubTitle:self.basicInfoModel.RECEPTION_NO];
    [self addSubview:oddNumber];
    
    //洗车
    NSString * wash_type = @"";
    if(!StrIsZero_gdm(self.basicInfoModel.WASH_TYPE)){
        wash_type = [ICrEAMTool getCodeModelForCode:self.basicInfoModel.WASH_TYPE].desc;
        
    }
    
    PreviewBaseItemView *washType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, oddNumber.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                     @"洗车" andSubTitle:wash_type];
    
    [self addSubview:washType];
    
    //旧件展示
    NSString * old_part_show = @"";
    if(!StrIsZero_gdm(self.basicInfoModel.OLD_PART_PROCESS)){
        old_part_show = [ICrEAMTool getCodeModelForCode:self.basicInfoModel.OLD_PART_PROCESS].desc;
        
    }
    
    PreviewBaseItemView *oldPartShow = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(washType.rightEdge, oddNumber.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                        @"旧件展示" andSubTitle:old_part_show];
    [self addSubview:oldPartShow];
    
    //备胎检查
    NSString * spare_wheel_check = @"";
    if(!StrIsZero_gdm(self.basicInfoModel.CHECK_SPARE_WHEEL)){
        spare_wheel_check = [ICrEAMTool getCodeModelForCode:self.basicInfoModel.CHECK_SPARE_WHEEL].desc;
        
    }
    PreviewBaseItemView *spareWheelCheck = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(oldPartShow.rightEdge, oddNumber.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                            @"备胎检查" andSubTitle:spare_wheel_check];
    [self addSubview:spareWheelCheck];
    
    
    //预约单号
    PreviewBaseItemView *appointmentNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(spareWheelCheck.rightEdge, oddNumber.bottomEdge+ActualHeight(10), ItemWidth, ItemHeight) andTitle:
                                           @"预约单号" andSubTitle:self.basicInfoModel.BOOKING_ORDER_NO];
    [self addSubview:appointmentNum];
    
    //需求描述
    PreviewBaseItemView *requirmentDescribe = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, appointmentNum.bottomEdge+ActualHeight(10), ItemWidth*2, ItemHeight) andTitle:
                                               @"需求描述" andSubTitle:self.basicInfoModel.BUSINESS_DESC];
    
    
    
    [self addSubview:requirmentDescribe];
    
    //送车地址
    PreviewBaseItemView *sendCarAddress = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(requirmentDescribe.rightEdge, appointmentNum.bottomEdge+ActualHeight(10), ItemWidth*2, ItemHeight) andTitle:
                                           @"送车地址" andSubTitle:self.basicInfoModel.DELIVER_ADD];
    [self addSubview:sendCarAddress];
    
    //故障描述
    if (self.repairEventModel.TT_RECPTION_LABOUR.count) {
        self.repairMaintenanceModel = [ICMRepairMaintenanceModel yy_modelWithDictionary:self.repairEventModel.TT_RECPTION_LABOUR[0]];
        
    }
    
    PreviewBaseItemView *faultDescribe = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, requirmentDescribe.bottomEdge+ActualHeight(10), ItemWidth*2, ItemHeight) andTitle:
                                          @"预计交车时间" andSubTitle:self.isInner?((!self.partsTopModel.DELIVERY_DATE || [self.partsTopModel.DELIVERY_DATE isEqualToString:@""])?@"":self.partsTopModel.DELIVERY_DATE):((!self.partsTopModel.DELIVERY_DATE || [self.partsTopModel.DELIVERY_DATE isEqualToString:@""])?@"":[ICrEAMTool getDateHourAndMinSecondWithTimeInterval:self.partsTopModel.DELIVERY_DATE])];
    [self addSubview:faultDescribe];
    
    //进一步检查
    PreviewBaseItemView *furtherCheck = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(requirmentDescribe.rightEdge, requirmentDescribe.bottomEdge+ActualHeight(10), ItemWidth*2, ItemHeight) andTitle:
                                         @"进一步检查" andSubTitle:self.basicInfoModel.DEPTH_CHECK];
    [self addSubview:furtherCheck];
    
    //分割块
    UIView *sperator1 = [[UIView alloc] initWithFrame:CGRectMake(0, furtherCheck.bottomEdge+ActualHeight(20), ScreenWidth, 1)];
    
    sperator1.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator1];
    
    
    UIView *block1 = [[UIView alloc] initWithFrame:CGRectMake(0, sperator1.bottomEdge, ScreenWidth, 13)];
    
    block1.backgroundColor = Color(0xf1f3f3);
    
    [self addSubview:block1];
    
    UIView *sperator2 = [[UIView alloc] initWithFrame:CGRectMake(0, block1.bottomEdge, ScreenWidth, 1)];
    
    sperator2.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator2];
    
    //4.外部检查
    //外部检查结果title
    UILabel *appearanceCheckLabel  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(20), furtherCheck.bottomEdge+ActualHeight(50), DisplayWidth, ActualHeight(20))];
    appearanceCheckLabel.textAlignment = NSTextAlignmentLeft;
    appearanceCheckLabel.text = @"外部检查结果";
    
    appearanceCheckLabel.textColor = TitleColor_Dark;
    appearanceCheckLabel.font = NaviFont;
    
    [self addSubview:appearanceCheckLabel];
    
    //第4行分割线
    UIView *fourthLine = [[UIView alloc] initWithFrame:CGRectMake(appearanceCheckLabel.x, appearanceCheckLabel.bottomEdge+ActualHeight(20), ActualWidth(1024)-carType.x, 1)];
    
    fourthLine.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:fourthLine];
    
    
    //外部检查布局
    self.checkView = [ICMAppearanceCheckView createAppearanceCheckViewWithFrame:CGRectMake(0, fourthLine.bottomEdge+ActualWidth(20), ActualWidth(1024), ActualHeight(700)) andIsfromPreview:YES];
    [self.checkView setupAppearanceCheckViewWithCheckAppearanceDownModel:self.checkAppearanceDownModel];
    self.checkView.backgroundColor = [UIColor blueColor];
    [self addSubview:self.checkView];
    [self setUpAppICMAppearanceCheckView];
    
    
    //5.套餐(XIB)
    PreviewPackageView *packageView = [[[NSBundle mainBundle]loadNibNamed:@"PreviewPackage" owner:self options:nil] firstObject];
    packageView.frame = CGRectMake(0, self.checkView.bottomEdge, ScreenWidth, ActualHeight(390));
    
    if([ICrEAMTool isVW])
    {
        [self addSubview:packageView];
    }
    
    //所选套餐
    packageView.selectedPackage.text = @"";
    packageView.packageDetail.text = @"";
    for(ICMCarePackageItemModel *model in self.carePackageModel.TT_RECPTION_PACKAGE_ITEM){
        
        //套餐名
        packageView.selectedPackage.text = model.PACKAGE_NAME;
        
        //所选套餐内容
        if(![packageView.packageDetail.text isEqualToString:@""])
            packageView.packageDetail.text = [packageView.packageDetail.text stringByAppendingString:@","];
        
        packageView.packageDetail.text = [packageView.packageDetail.text stringByAppendingString:model.PACKAGE_ITEM_NAME];
        NSString *oil = [NSString string];
        
        //机油种类显示
        for (ICMCarePackageThree_levelItemModel *mmm in model.OIL_TYPE) {
            if(IsStrEmpty(mmm.OIL_NAME)){
                oil = @"";
                
            }else{
                oil = mmm.OIL_NAME;
                NSString *fOil = [NSString stringWithFormat:@"(%@)",oil];
                packageView.packageDetail.text = [packageView.packageDetail.text stringByAppendingString:fOil];
                
            }

            
        }
        
        
        
        
        
        
    }
    //易损件
    packageView.quickWearPart.text = @"";
    if([self.carePackageDownModel.CONSUMABLE_WIPER isEqualToString:ICMEnumIntToString(ICMEnumYESOrNOYES)]){
        packageView.quickWearPart.text = [packageView.quickWearPart.text stringByAppendingString:@"雨刮"];
    }
    
    if([self.carePackageDownModel.CONSUMABLE_BRAKE_BLOCK isEqualToString:ICMEnumIntToString(ICMEnumYESOrNOYES)]){
        if(![packageView.quickWearPart.text isEqualToString:@""])
            packageView.quickWearPart.text = [packageView.quickWearPart.text stringByAppendingString:@","];
        
        if(![self.carePackageDownModel.CONSUMABLE_BRAKE_BLOCK_REMARK isEqualToString:@""])
            packageView.quickWearPart.text = [packageView.quickWearPart.text stringByAppendingFormat:@"%@(%@)",@"刹车片",self.carePackageDownModel.CONSUMABLE_BRAKE_BLOCK_REMARK];
        else
            packageView.quickWearPart.text = [packageView.quickWearPart.text stringByAppendingFormat:@"%@",@"刹车片"];
    }
    
    if([self.carePackageDownModel.CONSUMABLE_WHEEL isEqualToString:ICMEnumIntToString(ICMEnumYESOrNOYES)]){
        if(![packageView.quickWearPart.text isEqualToString:@""])
            packageView.quickWearPart.text = [packageView.quickWearPart.text stringByAppendingString:@","];
        
        if(![self.carePackageDownModel.CONSUMABLE_WHEEL_REMARK isEqualToString:@""])
            packageView.quickWearPart.text = [packageView.quickWearPart.text stringByAppendingFormat:@"%@(%@)",@"轮胎",self.carePackageDownModel.CONSUMABLE_WHEEL_REMARK];
        else
            packageView.quickWearPart.text = [packageView.quickWearPart.text stringByAppendingFormat:@"%@",@"轮胎"];
    }
    
    if([self.carePackageDownModel.CONSUMABLE_OTHER isEqualToString:ICMEnumIntToString(ICMEnumYESOrNOYES)]){
        if(![packageView.quickWearPart.text isEqualToString:@""])
            packageView.quickWearPart.text = [packageView.quickWearPart.text stringByAppendingString:@","];
        
        if(![self.carePackageDownModel.CONSUMABLE_OTHER_REMARK isEqualToString:@""])
            
            packageView.quickWearPart.text = [packageView.quickWearPart.text stringByAppendingFormat:@"%@(%@)",@"其他",self.carePackageDownModel.CONSUMABLE_OTHER_REMARK];
        else
            packageView.quickWearPart.text = [packageView.quickWearPart.text stringByAppendingFormat:@"%@",@"其他"];
        
    }
    //深度护养
    packageView.deepKeep.text = @"";
    
    if([self.carePackageDownModel.ENGINE_LUBRICATION isEqualToString:ICMEnumIntToString(ICMEnumYESOrNOYES)])
    {
        packageView.deepKeep.text = [packageView.deepKeep.text stringByAppendingString:@"发动机润滑,"];
    }
    if([self.carePackageDownModel.FUEL_SYSTEM_MAINTENANCE isEqualToString:ICMEnumIntToString(ICMEnumYESOrNOYES)])
    {
        
        packageView.deepKeep.text = [packageView.deepKeep.text stringByAppendingString:@"燃油系统养护,"];
    }
    if([self.carePackageDownModel.AIR_SYSTEM_MAINTENANCE isEqualToString:ICMEnumIntToString(ICMEnumYESOrNOYES)])
    {
        packageView.deepKeep.text = [packageView.deepKeep.text stringByAppendingString:@"进气系统养护,"];
    }
    if([self.carePackageDownModel.AIR_CONDITION_MAINTENANCE isEqualToString:ICMEnumIntToString(ICMEnumYESOrNOYES)])
    {
        packageView.deepKeep.text = [packageView.deepKeep.text stringByAppendingString:@"空调系统养护,"];
    }
    if(![packageView.deepKeep.text isEqualToString:@""])
        packageView.deepKeep.text = [packageView.deepKeep.text substringToIndex:    packageView.deepKeep.text.length-1];
    
    
    CGRect sperator5Rect = CGRectMake(0, packageView.bottomEdge+ActualHeight(30), ScreenWidth, 1);
    if([ICrEAMTool isVW])
    {
        sperator5Rect = CGRectMake(0, packageView.bottomEdge+ActualHeight(30), ScreenWidth, 1);
    }
    else
    {
        sperator5Rect = CGRectMake(0, self.checkView.bottomEdge, ScreenWidth, 1);
    }
    
    //分割块
    UIView *sperator5 = [[UIView alloc] initWithFrame:sperator5Rect];
    
    sperator5.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator5];
    
    
    UIView *block3 = [[UIView alloc] initWithFrame:CGRectMake(0, sperator5.bottomEdge, ScreenWidth, 13)];
    
    block3.backgroundColor = Color(0xf1f3f3);
    
    [self addSubview:block3];
    
    UIView *sperator6 = [[UIView alloc] initWithFrame:CGRectMake(0, block3.bottomEdge, ScreenWidth, 1)];
    
    sperator6.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator6];
    
    
    //6.所选活动
    //所选活动title
    UILabel *selectedActivity  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(20), sperator6.bottomEdge+ActualHeight(20), DisplayWidth, ActualHeight(20))];
    selectedActivity.textAlignment = NSTextAlignmentLeft;
    selectedActivity.textColor = [UIColor colorWithHex:0x000000];
    
    selectedActivity.textColor = TitleColor_Dark;
    selectedActivity.font = NaviFont;
    selectedActivity.text = @"所选活动";
    [self addSubview:selectedActivity];
    
    //第6行分割线
    UIView *sixthLine = [[UIView alloc] initWithFrame:CGRectMake(appearanceCheckLabel.x, selectedActivity.bottomEdge+ActualHeight(20), ActualWidth(1024)-carType.x, 1)];
    
    sixthLine.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sixthLine];
    PreviewActivityView *activity = [PreviewActivityView creatWithFrame:CGRectMake(ActualWidth(60), sixthLine.bottomEdge+ActualWidth(40), ScreenWidth-ActualWidth(60), self.activityModel.TT_RECPTION_ACTIVITY.count * ActualHeight(40)) dataSource:self.activityModel.TT_RECPTION_ACTIVITY];
    [self addSubview:activity];
    
    
//    for(int i = 0;i < self.activityModel.TT_RECPTION_ACTIVITY.count;i++){
//        
//        
//        CGFloat bottom = referActivityCode?referActivityCode.bottomEdge+ActualHeight(40):sixthLine.bottomEdge+ActualHeight(40);
//        
//        //活动名称
//        UILabel *activityName  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(60),bottom,ActualWidth(600),  ActualHeight(20))];
//        activityName.textAlignment = NSTextAlignmentLeft;
//        activityName.text = ((ICMActivityItemModel *)[self.activityModel.TT_RECPTION_ACTIVITY objectAtIndex:i]).ACTIVITY_NAME;
//        activityName.textColor = ContentTextColor_Gray;
//        [self addSubview:activityName];
//        
//        //活动代码
//        UILabel *activityCode  = [[UILabel alloc] initWithFrame:CGRectMake(activityName.rightEdge,bottom,ActualWidth(600),  ActualHeight(20))];
//        activityCode.textAlignment = NSTextAlignmentLeft;
//        activityCode.text = ((ICMActivityItemModel *)[self.activityModel.TT_RECPTION_ACTIVITY objectAtIndex:i]).ACTIVITY_CODE;        activityCode.textColor = ContentTextColor_Gray;
//        [self addSubview:activityCode];
//        
//        referActivityName = activityName;
//        referActivityCode = activityCode;
//    }
//    
//    //分割块
//    CGFloat bottom = referActivityCode?referActivityCode.bottomEdge+ActualHeight(35):sixthLine.bottomEdge+ActualHeight(35);
    
    UIView *sperator7 = [[UIView alloc] initWithFrame:CGRectMake(0,activity.bottomEdge+ActualHeight(35), ScreenWidth, 1)];
    
    sperator7.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator7];
    
    
    UIView *block4 = [[UIView alloc] initWithFrame:CGRectMake(0, sperator7.bottomEdge, ScreenWidth, 13)];
    
    block4.backgroundColor = Color(0xf1f3f3);
    
    [self addSubview:block4];
    
    UIView *sperator8 = [[UIView alloc] initWithFrame:CGRectMake(0, block4.bottomEdge, ScreenWidth, 1)];
    
    sperator8.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator8];
    
    //7.项目和零件
    //项目和零件title
    UILabel *projectTitle  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(20), sperator8.bottomEdge+ActualHeight(30), DisplayWidth, ActualHeight(20))];
    projectTitle.textAlignment = NSTextAlignmentLeft;
    projectTitle.text = @"项目和零件";
    projectTitle.textColor = TitleColor_Dark;
    projectTitle.font = NaviFont;
    [self addSubview:projectTitle];
    
    
    //合计
    UILabel *total  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(35), projectTitle.bottomEdge+ActualHeight(30), DisplayWidth, ActualHeight(35))];
    total.textAlignment = NSTextAlignmentLeft;
    total.textColor = TitleColor_Dark;
    total.text = @"    合计";
    total.backgroundColor = Color(0xf0f0f0);
    [self addSubview:total];
    
    
    
    //工时单价
    PreviewBaseItemView *pricePerH = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                      @"工时单价" andSubTitle:self.partsTopModel.LABOUR_PRICE];
    pricePerH.hidden = YES;
    [self addSubview:pricePerH];
    
//    float workingHoursTotal  = 0;
//    for (ICMRepairMaintenanceModel *model in self.repairEventModel.TT_RECPTION_LABOUR) {
//        workingHoursTotal += [model.STD_LABOUR_HOUR floatValue]*[[self calculateWorkingHoursWithSERIES_LABOUR_PRICE:self.SERIES_LABOUR_PRICE andREPAIR_ITEM_TYPE_RATE:model.REPAIR_ITEM_TYPE_RATE andTECHNIC_MODULUS:model.TECHNIC_MODULUS] doubleValue]?:0;
//    }
    
    //计算后台精度原因所造成的小数点后几位
//    NSString *LABOUR_AMOUNT = [self notRounding:[self.partsTopModel.LABOUR_AMOUNT floatValue] afterPoint:2];
//    NSString *TOTAL_AMOUNT = [self notRounding:[self.partsTopModel.TOTAL_AMOUNT floatValue] afterPoint:2];
//    NSString *RECEIVE_AMOUNT = [self notRounding:[self.partsTopModel.RECEIVE_AMOUNT floatValue] afterPoint:2];
//
//    self.partsTopModel.LABOUR_AMOUNT = LABOUR_AMOUNT;
//    self.partsTopModel.TOTAL_AMOUNT = TOTAL_AMOUNT;
//    self.partsTopModel.RECEIVE_AMOUNT = RECEIVE_AMOUNT;
    //工时费
    PreviewBaseItemView *workPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(pricePerH.rightEdge, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                      @"工时费" andSubTitle:self.partsTopModel.LABOUR_AMOUNT];
    
    [self addSubview:workPrice];
    
    //材料费
    PreviewBaseItemView *materialPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(workPrice.rightEdge, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                          @"零件费" andSubTitle:self.partsTopModel.REPAIR_PART_AMOUNT];
    
    [self addSubview:materialPrice];
    
    //总金额
    PreviewBaseItemView *totalPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(materialPrice.rightEdge, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                       @"总金额" andSubTitle:self.partsTopModel.TOTAL_AMOUNT];
    
    [self addSubview:totalPrice];
    
    //工时折旧率
    PreviewBaseItemView *workDesRate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance+ItemWidth, totalPrice.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                        @"工时折扣率" andSubTitle:self.partsTopModel.LABOUR_DISCOUNT_RATE];
    
    [self addSubview:workDesRate];
    
    //材料折旧率
    PreviewBaseItemView *materialDesRate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(workDesRate.rightEdge, totalPrice.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                            @"零件折扣率" andSubTitle:self.partsTopModel.PART_DISCOUNT_RATE];
    
    [self addSubview:materialDesRate];
    //折后总金额
    PreviewBaseItemView *afterPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(materialDesRate.rightEdge, totalPrice.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                       @"折后总金额" andSubTitle:self.partsTopModel.RECEIVE_AMOUNT];
    
    [self addSubview:afterPrice];
    
    
    self.endFrame = afterPrice.frame;
    
    // 排序
    NSMutableArray *labourArrayNew = [NSMutableArray new];
    for (ICMRepairMaintenanceModel *model in self.repairEventModel.TT_RECPTION_LABOUR) {
        if (StrIsZero_gdm(model.REPAIR_TYPE_NAME)) {
            return;
        }
        if (self.repairTypeNameLabour){
            if ([self.repairTypeNameLabour isEqualToString:model.REPAIR_TYPE_NAME]){
                [labourArrayNew addObject:model];
                if ([self.repairEventModel.TT_RECPTION_LABOUR indexOfObject:model] == (self.repairEventModel.TT_RECPTION_LABOUR.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                    [self.labourArray addObject:newArray];
                }
            }else{
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                [self.labourArray addObject:newArray];
                [labourArrayNew removeAllObjects];
                self.repairTypeNameLabour = model.REPAIR_TYPE_NAME;
                [labourArrayNew addObject:model];
                if ([self.repairEventModel.TT_RECPTION_LABOUR indexOfObject:model] == (self.repairEventModel.TT_RECPTION_LABOUR.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                    [self.labourArray addObject:newArray];
                }
            }
        }else{
            [labourArrayNew addObject:model];
            self.repairTypeNameLabour = model.REPAIR_TYPE_NAME;
            if ([self.repairEventModel.TT_RECPTION_LABOUR indexOfObject:model] == (self.repairEventModel.TT_RECPTION_LABOUR.count-1)) {
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                [self.labourArray addObject:newArray];
            }
        }
    }
    
    NSMutableArray *partArray = [NSMutableArray array];
    for (ICMRepairPartsModel *model in self.repairPartsModel.TT_RECPTION_PART) {
        if (StrIsZero_gdm(model.REPAIR_TYPE_NAME)) {
            return;
        }
        if (self.repairTypeNamePart) {
            if ([self.repairTypeNamePart isEqualToString:model.REPAIR_TYPE_NAME]) {
                [partArray addObject:model];
                if ([self.repairPartsModel.TT_RECPTION_PART indexOfObject:model] == (self.repairPartsModel.TT_RECPTION_PART.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                    [self.partArray addObject:newArray];
                }
            }else{
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                [self.partArray addObject:newArray];
                [partArray removeAllObjects];
                self.repairTypeNamePart = model.REPAIR_TYPE_NAME;
                [partArray addObject:model];
                if ([self.repairPartsModel.TT_RECPTION_PART indexOfObject:model] == (self.repairPartsModel.TT_RECPTION_PART.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                    [self.partArray addObject:newArray];
                }
            }
        }else{
            [partArray addObject:model];
            self.repairTypeNamePart = model.REPAIR_TYPE_NAME;
            if ([self.repairPartsModel.TT_RECPTION_PART indexOfObject:model] == (self.repairPartsModel.TT_RECPTION_PART.count-1)) {
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                [self.partArray addObject:newArray];
            }
        }
    }
    
    
    //8.底部 一般维修、常规保养
    
    if(self.labourArray && self.labourArray.count > 0)
    {
        for (int i = 0 ; i < self.labourArray.count; i++) {
            NSMutableArray *arrayItems = self.labourArray[i];
            ICMRepairMaintenanceModel *maintenanceModel = arrayItems[0];
            NSString *typeName = maintenanceModel.REPAIR_TYPE_NAME;
            NSMutableArray *arrayComps = [NSMutableArray array];
            for (NSMutableArray *array in self.partArray) {
                ICMRepairPartsModel *partsModel = array[0];
                if ([partsModel.REPAIR_TYPE_NAME isEqualToString:typeName]) {
                    arrayComps = array;
                }
            }
//            PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andStations:[NSArray array] andType:[NSString stringWithFormat:@"   %@",typeName]];
            PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andType:[NSString stringWithFormat:@"   %@",typeName]];
            [self addSubview:itemAndComponentViewFix];
            self.endFrame = itemAndComponentViewFix.frame;
            
        }
    }
    else
    {
        for (int i = 0 ; i < self.partArray.count; i++) {
            NSMutableArray *arrayComps = self.partArray[i];
            ICMRepairPartsModel *partsModel = arrayComps[0];
            NSString *typeName = partsModel.REPAIR_TYPE_NAME;
            NSMutableArray *arrayItems = [NSMutableArray array];
            for (NSMutableArray *array in self.labourArray) {
                ICMRepairMaintenanceModel *maintenanceModel = array[0];
                if ([maintenanceModel.REPAIR_TYPE_NAME isEqualToString:typeName]) {
                    arrayItems = array;
                }
            }
//            PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andStations:[NSArray array] andType:[NSString stringWithFormat:@"   %@",typeName]];
            PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andType:[NSString stringWithFormat:@"   %@",typeName]];
            [self addSubview:itemAndComponentViewFix];
            self.endFrame = itemAndComponentViewFix.frame;
            
        }
    }
  
//    //8.底部 一般维修、常规保养
//    //dummy data
//    NSMutableArray *arrayItems = self.repairEventModel.TT_RECPTION_LABOUR;
//    
//    NSMutableArray *arrayComps = self.repairPartsModel.TT_RECPTION_PART;
//    
//    PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, afterPrice.bottomEdge+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andType:@"   一般维修"];
//    [self addSubview:itemAndComponentViewFix];
//    
//    
//    PreviewItemAndComponentView *itemAndComponentViewCare = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, itemAndComponentViewFix.bottomEdge, ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andType:@"   常规保养"];
//    
//    [self addSubview:itemAndComponentViewCare];
    
}

-(void)setUpAppICMAppearanceCheckView{
    for (ICMPictureModel *model in self.checkAppearanceTopModel.TT_RECPTION_DAMANGE) {
        switch ([model.DAMAGE_TYPE integerValue]) {
            case 36001001:{
                self.checkView.innerImage = model.PIC_PATCH;
            }
                break;
            case 36001002:{
                [self.checkView.innerUrls addObject:model.PIC_PATCH];
            }
                break;
            case 36001003:{
                self.checkView.appearanceImage = model.PIC_PATCH;
            }
                break;
            case 36001004:{
                [self.checkView.appearanceUrls addObject:model.PIC_PATCH];
            }
                break;
                
            default:
                break;
        }
    }
    NSString *OWNER_NO = [NSString string];
    if(IsStrEmpty(self.basicInfoModel.OWNER_NO)){
        OWNER_NO = @"";
    
    }else{
        OWNER_NO = self.basicInfoModel.OWNER_NO;
    }
    NSDictionary *dic = @{@"VIN":self.basicInfoModel.VIN,
                          @"OWNER_NO":OWNER_NO
                          };
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"vinandonw" object:nil userInfo:dic];

    
    
    [self.checkView refreshInnerCollectionView];
    [self.checkView refreshAppearanceCollectionView];
}

- (void)clickPrintButton {
    if ([self.delegate respondsToSelector:@selector(print)]) {
        [self.delegate print];
    }
}
-(NSString *)calculateWorkingHoursWithSERIES_LABOUR_PRICE:(NSString *)SERIES_LABOUR_PRICE andREPAIR_ITEM_TYPE_RATE:(NSString *)REPAIR_ITEM_TYPE_RATE andTECHNIC_MODULUS:(NSString *)TECHNIC_MODULUS{
    
    double series_labour_price = [SERIES_LABOUR_PRICE floatValue];
    double repair_item_type_rate = [REPAIR_ITEM_TYPE_RATE floatValue];
    double texhnic_modulus = [TECHNIC_MODULUS floatValue];
    
    double workingHours = series_labour_price * repair_item_type_rate * texhnic_modulus;
    
    NSString *workingHoursStr = [NSString stringWithFormat:@"%.2f",workingHours];
    
    return workingHoursStr;
}
//格式话小数 四舍五入类型
- (NSString *) decimalwithFormat:(NSString *)format  floatV:(float)floatV
{
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    
    [numberFormatter setPositiveFormat:format];
    
    return  [numberFormatter stringFromNumber:[NSNumber numberWithFloat:floatV]];
}
-(NSString *)notRounding:(float)price afterPoint:(int)position{
    NSDecimalNumberHandler* roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain scale:position raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO];
    NSDecimalNumber *ouncesDecimal;
    NSDecimalNumber *roundedOunces;
                                   
    ouncesDecimal = [[NSDecimalNumber alloc] initWithFloat:price];
    roundedOunces = [ouncesDecimal decimalNumberByRoundingAccordingToBehavior:roundingBehavior];
    
    return [NSString stringWithFormat:@"%@",roundedOunces];
}
@end
